#include "../include/weight.h"

Weight::Weight(int doc_num, int ave_len, float param_b, float param_k1, float param_k2) :
    b_(param_b), k1_(param_k1), k2_(param_k2), doc_ave_len_(ave_len), doc_num_(doc_num) {
}

Weight::~Weight() {

}

float Weight::score_idf(const int df) const {
  return log((float) (doc_num_ - df + 0.5) / (df + 0.5));
}

float Weight::score_bm25(const int doc_id,
                         const int df,
                         const int tfq,
                         const int tfd,
                         const int doc_len) const {
  
  float s = (k1_ + 1) * tfd
      / (tfd + k1_ * (1 - b_ + b_ * (float) doc_len / doc_ave_len_)) * (k2_ + 1)
      * tfq / (k2_ + tfq) * log((float) (doc_num_ - df + 0.5) / (df + 0.5)); //TODO: idf
  
  return s;
}
